<?php

namespace controllers\admin;

use libs\request as request;
use libs\registry as Registry;


class konfiguracja extends \controllers\_SkyCMS_Controller
{
    private $_tabela = 'users';
    
    /**
     * @route=(/konfiguracja)
     */
    public function index()
    {
        $db = Registry::get("database");
        
        $user = $db->get_where($this->_tabela,array('login'=>$_SESSION['login']));
        
        return array('user'=>$user);
    }
    
    /**
     * @route=(/konfiguracja/zapisz)
     */
    public function zapisz()
    {
        $update = array();
        
        if(request::post('mail'))
        {
            $update['mail'] = request::post('mail');
        }
        
        if(request::post('haslo') and request::post('haslo') == request::post('haslo2'))
        {
            $haslo = md5('##'.request::post('haslo').'##');
            $update['haslo'] = $haslo;
        }
        
        $db = Registry::get("database");
        
        $result = $db->update($this->_tabela,$update,array('login'=>$_SESSION['login']
                ));
 
        return array();
    }
}
    
